from celery import Celery

# 在脚本中导入django环境
import os
import django
os.environ.setdefault('DJANGO_SETTINGS_MODULE','luffyapi.settings.dev')
django.setup()


backend = 'redis://127.0.0.1:6379/1'
broker = 'redis://127.0.0.1:6379/2'
app = Celery(__name__, broker=broker,backend=backend,
             include=['celery_task.course_task',
                      'celery_task.user_task',
                      'luffyapi.apps.home.home_task'])


# 修改时区
app.conf.timezone = 'Asia/Shanghai'
# 是否使用UTC
app.conf.enable_utc = False


# 执行定时任务(通过配置beat识别自己的配置，定时提交任务)
# 启动beat，启动worker
# celery -A celery_task beat -l info
# celery -A celery_task worker -l info -P eventlet

# 定时任务配置
from datetime import timedelta
from celery.schedules import crontab
app.conf.beat_schedule = {
    'update_banner': {
        'task': 'luffyapi.apps.home.home_task.update_banner',
        'schedule': timedelta(seconds=3)
    }
}